let baseUrl = "http://localhost:8081/shop_api";


$(document).ready(function(){ 
	let account = JSON.parse(sessionStorage.getItem("AccountInfo"));
	if(account!=null && account !=undefined){
		$(".tab-header a[href='index.html']").show();
		
	}else{
		$(".tab-header a[href='login.html']").show();
		$(".tab-header a[href='login.html?p=register']").show();
	}
});

function ajaxRequest(url,requestType,data,callback){
	$.ajax({
		url:baseUrl+url,
		type:requestType,
		data:data,
		dataType:'json',
		success:function(rst){
			callback(rst);
		},
		error:function(data){
			alert('网络错误!');
		}
	});
}

function ajaxRequestNotData(url,requestType,callback){
	$.ajax({
		url:baseUrl+url,
		type:requestType,
		dataType:'json',
		success:function(rst){
			callback(rst);
		},
		error:function(data){
			alert('网络错误!');
		}
	});
}

function returnFloat(value){
	var value=Math.round(parseFloat(value)*100)/100;
	var xsd=value.toString().split(".");
	if(xsd.length==1){
	value=value.toString()+".00";
	return value;
	}
	if(xsd.length>1){
	if(xsd[1].length<2){
	value=value.toString()+"0";
	}
	return value;
	}
}

function getQueryString(name) {  
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");  
	var r = window.location.search.substr(1).match(reg);  
	if (r != null) return unescape(r[2]);  
	return null;  
}

function paging(element){
	if(element.attr("data-value") === 'next'){
		let current = $(".page").children(".select");
		let next = current.next("a");
		next.addClass("select").siblings('a').removeClass("select");
		
		if(next.attr("data-value") === element.prev("a").attr("data-value")){
			element.addClass("disabled").siblings("a").removeClass("disabled");
		}
		return;
	}
	
	if(element.attr("data-value") === 'prev'){
		let current = $(".page").children(".select");
		let prev = current.prev("a");
		prev.addClass("select").siblings('a').removeClass("select");
		
		if(prev.attr("data-value") === element.next("a").attr("data-value")){
			element.addClass("disabled").siblings("a").removeClass("disabled");
		}
	}
	else{
		element.addClass("select").siblings('a').removeClass("select");

		if(element.attr("data-value") === $(".page a.prev").next("a").attr("data-value")){
			$(".page a.prev").addClass("disabled").siblings("a").removeClass("disabled");
		}
		
		if(element.attr("data-value") === $(".page a.next").prev("a").attr("data-value")){
			$(".page a.next").addClass("disabled").siblings("a").removeClass("disabled");
		}
	}
}